<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<base href="<%=basePath%>">
		<meta charset="utf-8" />
		<title></title>
		<meta name="description" content="overview & stats" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<link rel="stylesheet" href="static/css/bootstrap.min.css" />
		<link rel="stylesheet" href="static/css/bootstrap-responsive.min.css" />
		<link rel="stylesheet" href="static/css/font-awesome.min.css" />
		<link rel="stylesheet" href="static/css/ace.min.css" />
		<link rel="stylesheet" href="static/css/ace-responsive.min.css" />
		<link rel="stylesheet" href="static/css/ace-skins.min.css" />
		
		<script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
		<!--提示框-->
		<script type="text/javascript" src="static/js/jquery.tips.js"></script>
</head>

<script type="text/javascript">
	$(top.hangge());
	
	//保存
	function save(){
		if($("#cataname").val()==""){
			$("#cataname").tips({
				side:3,
	            msg:'请输入名称',
	            bg:'#AE81FF',
	            time:2
	        });
			
			$("#cataname").focus();
			return false;
		}
		
		if($("#cataname").val()=="" || $("#cataname").val()=="此编码已存在!"){
			$("#cataname").tips({
				side:3,
	            msg:'请输入编码',
	            bg:'#AE81FF',
	            time:2
	        });
			
			$("#cataname").focus();
			$("#cataname").val('');
			$("#cataname").css("background-color","white");
			return false;
		}
		
		if($("#sort").val()==""){
			$("#sort").tips({
				side:1,
	            msg:'请输入序号',
	            bg:'#AE81FF',
	            time:2
	        });
			
			$("#sort").focus();
			return false;
		}
		
		if(isNaN(Number($("#sort").val()))){
			$("#sort").tips({
				side:1,
	            msg:'请输入数字',
	            bg:'#AE81FF',
	            time:2
	        });
			
			$("#sort").focus();
			$("#sort").val(1);
			return false;
		}
		hasCataCode();
		
	}
	
	//判断编码是否存在
	function hasCataCode(){
		var cataid = $("#cataid").val();
		var catacode = $("#catacode").val();
		$.ajax({
			type : "PUT",
			url : "dictionary/hasCataCode/"+catacode+"/"+ cataid + ".json",
			//data:JSON.stringify(catacode),
			contentType:"application/json",  //发送至服务器的类型
			dataType : "json",     //预期服务器返回类型
			success: function(data){
				//alert(data.string);
				//return false;
				if(data.string=="error"){
					$("#catacode").css("background-color","#D16E6C");
					setTimeout("$('#catacode').val('此编码已存在!')",500);
				}else if(data.string=="hasDicionaryCount"){
					$("#catacode").css("background-color","#D16E6C");
					setTimeout("$('#catacode').val('不能修改，此目录下已存在字典!')",500);
				}else{
					$("#DictionaryCatalogForm").submit();
					$("#centerOfMainFrame").hide();
					$("#centerOfMainFrame2").show();
				}
			}
		})
	}
</script>
<body>
	<form action="dictionary/editDictionaryCatalog.do" name="DictionaryCatalogForm" id="DictionaryCatalogForm" method="post">
		<input type="hidden" name="cataid" id="cataid" value="${dictionaryCatalog.cataid }"/>
		<div id="centerOfMainFrame">
		<table>
			<tr class="info">
				<td><input type="text" name="cataname" id="cataname" placeholder="这里输入名称" value="${dictionaryCatalog.cataname }" title="名称"/></td>
			</tr>
			<tr class="info">
				<td><input type="text" name="catacode" id="catacode" placeholder="这里输入编码" value="${dictionaryCatalog.catacode }" title="编码"/></td>
			</tr>
			<tr class="info">
				<td><input type="number" name="sort" id="sort" placeholder="这里输入序号" value="${dictionaryCatalog.sort}" title="序号"/></td>
			</tr>
			<tr>
				<td style="text-align: center;">
					<a class="btn btn-mini btn-primary" onclick="save();">保存</a>
					<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
				</td>
			</tr>
		</table>
		</div>
		<div id="centerOfMainFrame2" class="center" style="display:none"><br/><br/><br/><img src="static/images/jzx.gif" style="width: 50px;" /><br/><h4 class="lighter block green"></h4></div>
	</form>
</body>
</html>